﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;

namespace Seym.Kontroller
{
    /// <summary>
    /// Interaction logic for Kutucuk.xaml
    /// </summary>
    public partial class Kutucuk : UserControl
    {
        private Koordinat _koor;
        private Storyboard stBoard;
        private static Kutucuk _bosKutu = new Kutucuk();

        public static readonly DependencyProperty SeciliMiProperty;

        public static Kutucuk BosKutu { get { return _bosKutu; } }
        public bool SilinecekMi { get; set; }
        public bool SeciliMi
        {
            get
            {
                return (bool)GetValue(SeciliMiProperty);
            }
            set
            {
                SetValue(SeciliMiProperty, value);
            }
        }

        public Koordinat Koordinat
        {
            get { return _koor; }
            set
            {
                _koor = value;

                this.Background = Yardimci.TurArkaplani(_koor.Tur);
            }
        }

        static Kutucuk()
        {
            SeciliMiProperty = DependencyProperty.Register(
                "SeciliMi", 
                typeof(bool), 
                typeof(Kutucuk), 
                new FrameworkPropertyMetadata(false, new PropertyChangedCallback(OnSeciliMiPropertChanged)));
        }

        public Kutucuk()
        {
            InitializeComponent();

            this.stBoard = (Storyboard)FindResource("SecimAnimasyon");
            this.DataContext = Properties.Settings.Default;
        }

        private static void OnSeciliMiPropertChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            Kutucuk k = (Kutucuk)sender;
            if ((bool)e.NewValue)
            {
                k.stBoard.Begin();
                k.SecimDortgeni.Visibility = Visibility.Visible;
            }
            else
            {
                k.stBoard.Pause();
                k.SecimDortgeni.Visibility = Visibility.Hidden;
            }
        }
    }
}
